<?php
/**
 * IdeasList.php
 * @author Winbeek <winbeek@gmail.com>
 * @since 28 July 2012
 * @version $Id$
 */

final class IdeasList extends Nette\Application\UI\Control {
	/** @var \Nette\Database\Table\Selection $accounts */
	private $accounts;

	/** @var \Nette\Database\Table\Selection $ideas */
	private $ideas;

	/**
	 * @param \Nette\Database\Table\Selection $ideas
	 * @param \Nette\Database\Table\Selection $accounts
	 */
	public function __construct(Nette\Database\Table\Selection $ideas, Nette\Database\Table\Selection $accounts)
	{
		$this->accounts = $accounts;
		$this->ideas = $ideas;
	}

	public function render()
	{
		$this->template->ideas = $this->ideas;

		$this->template->setFile(__DIR__ . '/IdeasList.latte');
		$this->template->render();
	}

	protected function createComponentIdea()
	{
		$accounts = $this->accounts;
		$ideas = $this->ideas;
		return new Nette\Application\UI\Multiplier(function ($ideaId) use ($accounts, $ideas) {
			return new Idea($ideas[$ideaId], $accounts[$ideas[$ideaId]->id]);
		});
	}
}